package com.yumis.service.modules.car.service.Impl;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.exception.GlobalException;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.CategoryParts;
import com.yumis.service.model.pojo.CategoryService;
import com.yumis.service.modules.car.mapper.CategoryServiceMapper;
import com.yumis.service.modules.car.service.CategoryServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CategoryServiceServiceImpl implements CategoryServiceService {
    @Resource
    private CategoryServiceMapper categoryServiceMapper;
    @Override
    public void addCategoryService(CategoryService categoryService) {
        int i=categoryServiceMapper.insertSelective(categoryService);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.CREATED_FAILED));
        }
    }

    @Override
    public void deleteCategoryServiceById(Long id) {
        int i=categoryServiceMapper.deleteByPrimaryKey(id);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.DELETE_ERROR));
        }
    }

    @Override
    public void updateCategoryService(CategoryService categoryService) {
        int i=categoryServiceMapper.updateByPrimaryKeySelective(categoryService);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.UPDATE_ERROR));
        }
    }

    @Override
    public CategoryService queryCategoryServiceById(Long id) {
        CategoryService categoryService=categoryServiceMapper.selectByPrimaryKey(id);
        if (categoryService ==null || categoryService.equals("") ){
            throw new GlobalException(Response.buildResponse(HttpState.DATA_NOT_FOUNT));
        }
        return categoryService;
    }
}
